package com.qike.duola.utils;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public final class FileUtil {



    public static String getFileName(String filePath) {
        if (StringUtils.isEmpty(filePath)){
            return null;
        }
        String fileName = null;
        String[] split = filePath.split(",");
        for (String s : split) {
            String substring = s.substring(s.lastIndexOf("/") + 1);
            fileName = substring+",";
        }
        fileName.substring(0,fileName.length() -1);
        return fileName;
    }

    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid){

        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);

        return geoCurve.getEllipsoidalDistance();
    }
}
